package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JiCaiQuotedPriceCompanyEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * 报价内容页面列表适配器
 */
public class QuotedContentAdapter extends BaseRecycleAdapter<JiCaiQuotedPriceCompanyEntity.RecordsDataEntity> {
    private Context context;

    public QuotedContentAdapter(Context context, List<JiCaiQuotedPriceCompanyEntity.RecordsDataEntity> datas) {
        super(context, R.layout.item_quotedprice_content, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, JiCaiQuotedPriceCompanyEntity.RecordsDataEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView guige = holder.itemView.findViewById(R.id.guige);
        LinearLayout llgoods = holder.itemView.findViewById(R.id.ll_goods);
        if (entity.getShoptype() == 1){
            llgoods.setVisibility(View.VISIBLE);
        }else {
            llgoods.setVisibility(View.GONE);
        }
        if (entity.getAttr()!=null&&entity.getAttr().size()>0){
            StringBuilder stringattr = new StringBuilder();
            for (JiCaiQuotedPriceCompanyEntity.AttrsBean attrBean : entity.getAttr()) {
                if (!TextUtils.isEmpty(attrBean.getValue())){
                    stringattr.append(attrBean.getName()).append(":").append(attrBean.getValue()).append(" ");
                }
            }
            if (!TextUtils.isEmpty(stringattr.toString())){
                guige.setText(stringattr.toString());
            }else {
                guige.setText("无");
            }
        }else {
            guige.setText("无");
        }
      //  updateRecycler(((ItemQuotedpriceContentBinding) holder.getmBinding()).childRecycler, entity);
    }

    //更新子列表显示
    private void updateRecycler(RecyclerView recyclerView, JiCaiQuotedPriceCompanyEntity.RecordsDataEntity entity) {
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        QuotedContentChildItemAdapter childAdapter = new QuotedContentChildItemAdapter(recyclerView.getContext(), entity.getPriceRule(), entity.getUnitName(), entity.getPriceWarning());
        recyclerView.setAdapter(childAdapter);
    }

}
